package mbp.tests;

import java.io.IOException;

import mbp.base.MessageType;
import mbp.core.Resource;

import jade.core.AID;
import jade.core.Agent;
import jade.lang.acl.ACLMessage;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import jade.wrapper.StaleProxyException;

/**
 * 
 * @author Wojciech Wilanski
 *
 */
public class ResourceAgent  extends Agent
{
	protected void setup()
	{
		System.out.println("ResourceAgent " + getAID().getName()+" is ready.");
		
		ResourceAgentGui agentGui = new ResourceAgentGui(this);
		agentGui.showGui();
		
		AgentContainer ac = getContainerController();
		try {
			AgentController receiver = ac.createNewAgent("receiver", "mbp.tests.ReceiverAgent", null);
			receiver.start();
		} catch (StaleProxyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/*
	public void SendResource(iResource resource, String agentName)
	{
		//System.out.println("Not implemented yet.");
		ACLMessage msg = new ACLMessage(ACLMessage.CFP);
		msg.addReceiver( new AID(agentName, AID.ISLOCALNAME));
		msg.setSender(new AID(this.getLocalName(), AID.ISLOCALNAME));
		
		try {
			msg.setContentObject(resource);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		send(msg);
	}
	*/
	
	public void SendResource(Resource resource, String agentName)
	{
		mbp.message.Message iMsg = new mbp.message.Message(MessageType.RESOURCE, this.getLocalName(), agentName);
		iMsg.setResource(resource);
		send(iMsg.GetACLMessage());
	}
	

}
